package org.atovio.coolexam.service.impl;

import org.atovio.coolexam.entity.QuestionOptions;
import org.atovio.coolexam.mapper.QuestionOptionsMapper;
import org.atovio.coolexam.service.QuestionOptionsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class QuestionOptionsServiceImpl implements QuestionOptionsService {

    private final QuestionOptionsMapper questionOptionsMapper;

    @Autowired
    public QuestionOptionsServiceImpl(QuestionOptionsMapper questionOptionsMapper) {
        this.questionOptionsMapper = questionOptionsMapper;
    }

    @Override
    public int add(QuestionOptions questionOptions) {
        return questionOptionsMapper.insert(questionOptions);
    }

    @Override
    public void modifyContent(QuestionOptions questionOptions) {
        questionOptionsMapper.updateContentById(questionOptions.getId(), questionOptions.getContent());
        questionOptionsMapper.updateOrderById(questionOptions.getId(), questionOptions.getOrder());
    }

    @Override
    public List<QuestionOptions> getAll() {
        return questionOptionsMapper.selectAll();
    }

    @Override
    public QuestionOptions getById(int id) {
        return questionOptionsMapper.selectById(id);
    }

    @Override
    public List<QuestionOptions> getByQuestionId(int questionId) {
        return questionOptionsMapper.selectByQuestionId(questionId);
    }
}
